from django.contrib import admin
from django.utils.html import format_html

from . import models


@admin.register(models.Account)
class AccountAdmin(admin.ModelAdmin):
    list_display = ['uid', 'username', 'get_avatar', 'is_active', 'is_staff', 'crete_time', 'last_login']
    list_filter = ["username", 'is_active', 'is_staff']
    search_fields = ['username']
    list_max_show_all = 100
    list_per_page = 20

    def get_avatar(self, obj):
        return format_html(f'<img src="{obj.avatar}" width="50" height="50">')

    get_avatar.short_description = '头像'
